var CheXingTable;
/****列表信息*/
function showCheXingList() {
	showLoading("查询中...");
	$.ajax( {
		url : 'cheXing/listPage.do',
		type : 'get',
		async:true,
		dataType : 'html',
		success : function(html) {
			$('#mainForm').html(html);
			queryChexDatas();
			hideLoading();
			//绑定查询按钮 
		$('#searchCheXingBtn').click(function() {
			queryChexDatas();
		});
	}
	});
}

function queryChexDatas(){
	CheXingTable = $('#entTable').table( {
				width : '100%',
				defaultOrderBy:"sort",
		defaultOrderType:"asc",
				form : {
					url : 'comm/search.do',
					id : '#entSearchForm',
					type : 'post',
					pageNumberText : '#pageNum'
				},
				pageable : true,
				selectable : true,

				colums : [ {
					columnName : '车型名称',
					name : 'name',
					handle:"toAddCheXing"
				}, {
					columnName : '创建时间',
					name : 'crateDate'
				}, {
					columnName : '更新时间',
					name : 'updateDate'
				}, {
					columnName : '显示状态',
					name : 'state',
					formatter:function(obj){
					if(obj.state=='1'){
						return "显示";
					}else if(obj.state=='0'){
						return "不显示";
					}else{
						return "";
					}
				}
				}]
			});
}

//去增加
function toAddCheXing(id) {
	var param = '?t='+ts();
	if (id) {
		param += '&id=' + id;
	}
	$.get('cheXing/toAddCheXing.do' + param, function(html) {
		$('#commonDialogDiv').html(html);
		$('#commonDialogDiv').dialog( {
			modal : true,
			title : '车型信息维护',
			width : 995,
			height : 600,
			buttons : {
				'保存' : function() {
					saveAddCheXing();
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			},close:function(){$(this).dialog('destroy');}
		});

		addValidatorInteger();
		validator = $("#CheXingForm").validate( {
			rules : {
				"model.name" : {
					required : true,
					maxlength : 20
				},
				"model.detailInfo":{
					maxlength : 150
				},
				"model.sort":{
					required : true,
					integer:true
				}
			},
			messages : {
				"model.name" : {
					required : "必填"
				},
				"model.detailInfo":{
					maxlength : "最多能写150个字"
				},
				"model.sort":{
					required : "必填",
					integer : "只能填写大于0数字"
				}
			}
		});
	});
}
//去保存
function saveAddCheXing() {
	if (validator.form()) {
		$('#CheXingForm').ajaxSubmit( {
			url : 'cheXing/saveCheXing.do',
			type : 'post',
			dataType : 'json',
			success : function(data) {
				if (data.success) {
					showDialog('保存成功');
					$('#commonDialogDiv').dialog('close');
					CheXingTable.refresh();
				} else {
					showDialog('保存失败' + data.message);
				}
			}
		});
	}
}

//批量删除 
function toDeleteCheXing() {
	var ids = '';
	$('.ids').each(function() {
		if (this.checked == true) {
			ids += 'ids=' + this.value + '&';
		}
	});
	if (ids.length == 0) {
		showDialog('请至少选择一条记录！');
		return;
	}
	$('#commonDialogDiv').html('<p>确定要删除记录信息？</p>');
	$('#commonDialogDiv').dialog( {
		modal : true,
		width : 250,
		height : 160,
		buttons : {
			'确定' : function() {
				$(this).dialog('close');
				$.ajax( {
					url : 'cheXing/delete.do?' + ids,
					type : 'get',
					dataType : 'json',
					success : function(data) {
						if (data.success) {
							CheXingTable.refresh();
						} else {
							showDialog('删除失败，原因：' + data.message);
						}
					}
				});
			},
			'取消' : function() {
				$(this).dialog('close');
			}
		},close:function(){$(this).dialog('destroy');}
	});
}
